package com.emex.app.stuff.provider;

import com.emex.app.shared.data.Profit;
import com.emex.app.shared.data.ProfitType;
import com.emex.app.shared.ws.ProfitWebService;
import com.emex.app.stuff.utils.WebServiceHelper;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.List;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;

/**
 *
 * @author Sergey Karavaev
 */
public class ProfitDataProvider extends Service {

    private ProfitWebService service = null;

    private static ProfitDataProvider instance = null;

    /**
     * Constructor
     */
    private ProfitDataProvider() throws MalformedURLException {
        super(new URL(WebServiceHelper.getDefault().getWebServiceURL("web", "Profit")),
                WebServiceHelper.getDefault().getWebServiceQName("Profit"));
        service = getPort(ProfitWebService.class);
    }

    /**
     * Get instance of data provider.
     *
     * @return data provider instance
     */
    public static synchronized ProfitDataProvider getInstance() {
        if (instance == null) {
            new RequestWebService() {
                @Override
                protected void doRequestBody() throws MalformedURLException {
                    instance = new ProfitDataProvider();
                }
            }.doRequest();
        }
        return instance;
    }

    public BindingProvider getBindingProvider() {
        return (BindingProvider) service;
    }

    public int deleteProfitByPrimaryKey(Integer id) {
        return service.deleteProfitByPrimaryKey(id);
    }

    public Profit insertProfit(Profit record) {
        return service.insertProfit(record);
    }

    public Profit selectProfitByPrimaryKey(Integer id) {
        return service.selectProfitByPrimaryKey(id);
    }

    public Profit updateProfitByPrimaryKey(Profit record) {
        record = service.updateProfitByPrimaryKey(record);
        return record;
    }

    public List<Profit> getAllProfitsByDate(Date date) {
        return service.getAllProfitsByDate(date);
    }

    public int deleteProfitTypeByPrimaryKey(Integer id) {
        return service.deleteProfitTypeByPrimaryKey(id);
    }

    public ProfitType insertProfitType(ProfitType record) {
        return service.insertProfitType(record);
    }

    public List<ProfitType> getAllProfitTypes() {
        return service.getAllProfitTypes();
    }

    public ProfitType updateProfitType(ProfitType record) {
        return service.updateProfitType(record);
    }

    public ProfitType selectProfitTypeByPrimaryKey(Integer id) {
        return service.selectProfitTypeByPrimaryKey(id);
    }

    public List<Profit> getAllProfitsByDateAndProfitType(Date startDate, Date endDate, Integer profitTypeId) {
        return service.getAllProfitsByDateAndProfitType(startDate, endDate, profitTypeId);
    }

    public List<Profit> getAllProfitsByDateEqualOrGraterThan(Date date) {
        return service.getAllProfitsByDateEqualOrGraterThan(date);
    }
}